package com.anlu.base.common.core.config;

import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.client.RestClient;
import org.springframework.web.client.RestTemplate;

@AutoConfiguration
public class RestTemplateConfiguration {

    @Bean
    @LoadBalanced
    @ConditionalOnProperty(value = "spring.cloud.nacos.discovery.enabled", havingValue = "true", matchIfMissing = true)
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

    /**
     * REST 客户端构建器（支持负载均衡）
     * @return {@link RestClient.Builder }
     */
    @Bean
    @LoadBalanced
    @ConditionalOnProperty(value = "spring.cloud.nacos.discovery.enabled", havingValue = "true", matchIfMissing = true)
    RestClient.Builder restClientBuilder() {
        return RestClient.builder();
    }
}
